#include "StdAfx.h"
#include "DBTableUserCL.h"
#include "DBManagerCL.h"

DBTableUserCL::DBTableUserCL(Database * pDataBase_)
:DBTableBaseCL(pDataBase_)
{
	this->SetTableName("Game_User") ;
}

DBTableUserCL::~DBTableUserCL(void)
{
}

unsigned int DBTableUserCL::IsUserPermission(std::string userName_ , std::string passWord_)
{
	Query q(*m_pDataBase) ;
	
	unsigned int retI = 0 ;
	if(q.Connected() == true)
	{
		std::string sql ;
		sql = "select * from " + this->GetTableName() + " where (UserName = '" + userName_ + "') and ( PassWord = '" + passWord_ + "')" ;
		if(q.get_result(sql) == true)
		{
			if(q.fetch_row() == true)
			{
				retI = q.getval(0) ;
			}
			q.free_result() ;
		}
	}

    return retI ;
}

::DBServerProtocal::UserInfo DBTableUserCL::GetUserInfo(unsigned int userID_)
{
	Query q(*m_pDataBase) ;
	
	::DBServerProtocal::UserInfo info ;
	if(q.Connected() == true)
	{
		std::string sql ;
		char temp[255] ;
		sprintf(temp , "%d" , userID_) ;
		sql = "select * from " + this->GetTableName() + " where (UserID = '" + std::string(temp) + "') " ;
		if(q.get_result(sql) == true)
		{
			if(q.fetch_row() == true)
			{
				info.userID   = q.getval(0) ;
				info.userName = ToSafeStr(q.getstr(1)) ;
				info.passWord = ToSafeStr(q.getstr(2)) ;
				info.birthDay = ToSafeStr(q.getstr(3)) ;
				info.IDCard   = ToSafeStr(q.getstr(4)) ;
			}
			q.free_result() ;
		}
	}

	return info ;
}